package com.frog.rss.facade;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;

import com.frog.rss.RSSHelper;
import com.frog.rss.dao.RSSItemDao;
import com.frog.rss.domain.RSSItem;

public class RSSFacade {

	public List<RSSItem> loadRSSItemsFromWWW(String feedUrl) {
		try {
			return RSSHelper.loadRssItems((new URL(feedUrl)));
		} catch (MalformedURLException e) {
			Log.d(RSSFacade.class.getName(), e.getMessage());
			return new ArrayList<RSSItem>();
		}
	}

	public void saveRSSItemsToDB(Context context, List<RSSItem> rssItems) {
		RSSItemDao rssItemDao = new RSSItemDao(context);
		for (RSSItem each : rssItems) {
			rssItemDao.insert(each);
		}
	}
	public List<RSSItem> loadRSSItemsFromDB(Context context){
		RSSItemDao rssItemDao = new RSSItemDao(context);
		return rssItemDao.loadAllRssItems();
	}
}
